# Contributor: Leo <thinkabit.ukim@gmail.com>
# Maintainer: Leonardo Arena <rnalrd@alpinelinux.org>
pkgname=weechat
pkgver=4.1.2
pkgrel=2
pkgdesc="Fast, light, extensible ncurses-based chat client"
url="https://weechat.org"
arch="all"
options="!check" # test suite runs "sudo make install"
license="GPL-3.0-or-later"
depends_dev="
	aspell-dev
	curl-dev
	gettext-dev
	gnutls-dev
	libgcrypt-dev
	lua-dev
	ncurses-dev
	perl-dev
	python3-dev
	zlib-dev
	zstd-dev
	"
makedepends="
	$depends_dev
	asciidoctor
	cmake
	samurai
	"
subpackages="
	$pkgname-dev
	$pkgname-doc
	$pkgname-lang
	$pkgname-spell:_plugin
	$pkgname-lua:_plugin
	$pkgname-perl
	$pkgname-python:_plugin
	"
source="https://www.weechat.org/files/src/weechat-$pkgver.tar.xz
	ruby-3.3-compat.patch
	"

# secfixes:
#   1.7.1-r0:
#     - CVE-2017-8073
#   1.9.1-r0:
#     - CVE-2017-14727
#   2.7.1-r0:
#     - CVE-2020-8955

build() {
	cmake -B build -G Ninja \
		-DCMAKE_BUILD_TYPE=None \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DENABLE_MAN=ON \
		-DENABLE_TCL=OFF \
		-DENABLE_GUILE=OFF \
		-DENABLE_JAVASCRIPT=OFF \
		-DENABLE_PHP=OFF \
		-DENABLE_RUBY=OFF
	cmake --build build
}

check() {
	./tools/build-test.sh cmake
}

package() {
	DESTDIR="$pkgdir" cmake --install build
}

_plugin() {
	local _name=${subpkgname#*-}
	local _dir=usr/lib/weechat/plugins

	pkgdesc="WeeChat $_name plugin"
	depends="weechat"

	# as of 2.5 aspell has been renamed to spell on weechat upstream
	# since it now supports enchant as well, rename the subpackage and
	# replace the old one
	if [ "$_name" = spell ]; then
		replaces="$pkgname-aspell"
		provides="$pkgname-aspell=$pkgver-r$pkgrel"
	fi

	amove $_dir/"$_name".so
}

perl() {
	_plugin
	depends="$depends perl-pod-parser"
}

sha512sums="
9df8b43a7210f06cece1d28fcf8559885a0d5590b5691f63205b215417f132e4d74f4af18b572daae2679d5cf574b61538a7067e03087be10e831fee4f55e115  weechat-4.1.2.tar.xz
3fa8241fc326645cb0ffb7ef89bf4787b27d715d2cf40d74971faee78e6dc2509c2a3bf6f8f9eb62af9c0c8b910a3079d7473469d69dcdb9988659c1b9dee683  ruby-3.3-compat.patch
"
